//
// Created by tatyx on 2025/8/26.
//

#ifndef GC_30_DM_G6220_H
#define GC_30_DM_G6220_H

#include "main.h"
#include "fdcan.h"
#include "Ano_pid.h"
#include "usart.h"

typedef struct
{
    float position;      //(-12.57f~12.57f)rad
    float velocity;   //(-31.4rad/s~31.4rad/s)
    float Torque;     //（-18Nm~-18Nm）
    float temprrature;//

    u8 motorID;
}DM_TypeDef;
typedef struct
{
    FDCAN_HandleTypeDef *hcan;
    FDCAN_TxHeaderTypeDef Header;
    uint8_t Data[8];
}FDCAN2_TxFrame_TypeDef;
typedef struct
{
    FDCAN_HandleTypeDef *hcan;
    FDCAN_RxHeaderTypeDef Header;
    uint8_t Data[8];
}FDCAN2_RxFrame_TypeDef;

void DM_Enable_motor(DM_TypeDef *motor );
void DM_DisEnable_motor(DM_TypeDef *motor);
void DM_Keep_zero(DM_TypeDef *motor);
void DM_Clear_error(DM_TypeDef *motor);

void DM_Mode_mit(DM_TypeDef *motor, float _pos, float _vel, float _KP, float _KD, float _torq);
void DM_Data_deal(FDCAN2_RxFrame_TypeDef *RxFrame);
void DM6220_speed_mit(float Speed);
void DM6220_postion_mit(float position, float speed);
#endif //GC_30_DM_G6220_H